Imports System
Imports System.Collections.Generic
Imports System.Text


Class Expressplus

    Private Function returnstring(ByVal identifier As String, ByVal source As String) As String

        Dim index As Integer = 0
        Dim num2 As Integer = 0
        Dim ch As String = Chr(1D)
        index = source.IndexOf(identifier)
        index = source.IndexOf(ch, index + 1)
        num2 = source.IndexOf(ch, index + 1)
        Return source.Substring(index + 1, num2 - index - 1)
    End Function

    Public Sub demographic(ByRef re As String, ByVal iden As String, ByVal soucrce As String)

        re = returnstring(iden, soucrce)
    End Sub
    Public Function testresult(ByRef value As String, ByRef unit As String, ByRef exception As String, ByVal testtype As String, ByVal source As String) As Boolean

        Dim index As Integer = 0
        Dim num2 As Integer = 0
        Dim num3 As Integer = 0
        Dim num4 As Integer = 0
        Dim ch As Char = Chr(1D)
        Dim ch2 As String = Chr(17)
        testtype = "TS=" & testtype

        index = source.IndexOf(testtype)
        If (index = -1) Then

            Return False
        End If
        index = source.IndexOf(ch, index + 1)
        num2 = source.IndexOf(ch, index + 1)
        num3 = source.IndexOf(ch, num2 + 1)
        num4 = source.IndexOf(ch2, num2 + 1)
        value = source.Substring(index + 1, num2 - index - 1)
        unit = source.Substring(num2 + 1, num3 - num2 - 1)
        If (num4 <> -1) Then

            exception = source.Substring(num3 + 1, num4 - num3)

        Else

            exception = ""
        End If
        Return True


    End Function
    Private Function traytoString(ByVal input As Integer) As String

        Select Case input

            Case 1
                Return "A"

            Case 2
                Return "B"

            Case 3
                Return "C"

            Case 4
                Return "D"

            Case 5
                Return "E"

            Case 6
                Return "F"

            Case 7
                Return "G"

            Case 8
                Return "H"

            Case 9
                Return "I"
        End Select
        Return ""
    End Function
    Private Function valueint(ByVal input As String) As Integer

        Dim num As Integer = 0
        Dim num2 As Integer = 1
        Dim i As Integer = 0
        For i = 0 To input.Length - 1


            num += chartoint(input((input.Length - i) - 1)) * num2
            num2 *= 10
        Next
        Return num
    End Function



    Private Function chartoint(ByVal c As String) As Integer
        Select Case c

            Case "0"
                Return 0

            Case "1"
                Return 1

            Case "2"
                Return 2

            Case "3"
                Return 3

            Case "4"
                Return 4

            Case "5"
                Return 5

            Case "6"
                Return 6

            Case "7"
                Return 7

            Case "8"
                Return 8

            Case "9"
                Return 9
        End Select
        Return 0
    End Function

    Public Function finding(ByRef tray As String, ByRef cup As String, ByVal cupnumber As String) As Boolean
        Dim num As Integer = 0
        Dim num2 As Integer = 0
        Dim input As Integer = 0

        num = valueint(cupnumber)
        If (num > 360) Then

            tray = ""
            cup = ""
            Return False
        End If

        input = ((((num - 40) / 40) + ((num + 40) / 40)) / 2) + 1
        num2 = num - ((input - 1) * 40)
        tray = traytoString(input)
        cup = num2.ToString()
        Return True
    End Function
    Private Function hexa(ByVal input As Integer) As String

        If (input < 10) Then

            Return input.ToString()
        End If
        Select Case input

            Case 10
                Return "A"

            Case 11
                Return "B"

            Case 12
                Return "C"

            Case 13
                Return "D"

            Case 14
                Return "E"

            Case 15
                Return "F"
        End Select

        Return ""
    End Function


    Public Function CheckACK(ByVal strInput As String) As Boolean

        Dim ch As String = Chr(2)
        Dim ch2 As String = Chr(3)
        Dim ch3 As String = Chr(4)
        Dim startIndex As Integer = 0
        Dim index As Integer = 0
        Dim num3 As Integer = 0
        Dim num4 As Integer = 0
        Dim num5 As Integer = 0
        Dim num6 As Integer = 0
        Dim text As String = ""
        Dim text2 As String = ""
        startIndex = strInput.IndexOf(ch)
        index = strInput.IndexOf(ch2)
        If (startIndex = -1) Then

            Return False
        End If
        If (index = -1) Then

            Return False
        End If
        text2 = strInput.Substring(startIndex, (index + 1) - startIndex)
        Dim chArray() As Char = text2.ToCharArray(0, text2.Length)
        For Each s As Char In chArray

            num3 += Asc(s)
        Next
        num4 = num3 Mod 256
        num5 = num4 \ 16
        num6 = num4 Mod 16
        text = hexa(num5) + hexa(num6)
        startIndex = strInput.IndexOf(ch3)
        If (startIndex = -1) Then

            Return False
        End If
        Return (strInput.Substring(index + 1, (startIndex - 1) - index) = text)
    End Function

End Class

